home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
4490
/
4490.xpi
/
chrome
/
wmn.jar
/
content
/
alert.js
< prev
next >
Wrap
Text File
|
2010-01-30
|
7KB
|
222 lines
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Scott MacGregor <mscott@netscape.com>
* Jens Bannmann <jens.b@web.de>
* Byungwook Kang <tobwithu@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Copied from nsILookAndFeel.h, see comments on eMetric_AlertNotificationOrigin
const NS_ALERT_HORIZONTAL = 1;
const NS_ALERT_LEFT = 2;
const NS_ALERT_TOP = 4;
var gFinalSize;
var gCurrentSize = 1;
var gSlideIncrement = 1;
var gSlideTime = 10;
var gOpenTime = 4000; // total time the alert should stay up once we are done animating.
var gOrigin = 0; // Default value: alert from bottom right, sliding in vertically.
var gAlertListener = null;
var gAlertTextClickable = false;
var gAlertCookie = "";
var wmn=null;
var timer;
var timerFunc;
const dout=Components.utils.reportError;
function setTimer(func,time){
var o={
notify:function(aTimer){
func();
}
};
timer.initWithCallback(o,time,Components.interfaces.nsITimer.TYPE_ONE_SHOT);
}
function prefillAlertInfo()
{
wmn=window.arguments[1];
var obj=document.getElementById("alertTextBox");
var info=window.arguments[0];
var close=true;
for(var i=0;i<info.length;i++){
var o=info[i];
var n;
if(o.enabled&&(n=o.calcCount())>0){
var em = document.createElement("label");
em.setAttribute("value",o.accName+" : "+o.mailData.desc);
em.setAttribute("class","alertText plain");
em.setAttribute("onclick","wmn.openMail("+i+",null)");
obj.appendChild(em);
close=false;
}
}
if(close)window.close();
}
function onAlertLoad()
{
// Read out our initial settings from prefs.
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService();
prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
var prefBranch = prefService.getBranch(null);
try
{
gSlideIncrement = prefBranch.getIntPref("alerts.slideIncrement");
gSlideTime = prefBranch.getIntPref("alerts.slideIncrementTime");
gOpenTime = prefBranch.getIntPref("alerts.totalOpenTime");
}
catch (ex){}
if(prefBranch.getBoolPref("extensions.wmn.keepAlert"))gOpenTime=0;
timer = Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
// Make sure that the contents are fixed at the window edge facing the
// screen's center so that the window looks like "sliding in" and not
// like "unfolding". The default packing of "start" only works for
// vertical-bottom and horizontal-right positions, so we change it here.
if (gOrigin & NS_ALERT_HORIZONTAL)
{
if (gOrigin & NS_ALERT_LEFT)
document.documentElement.pack = "end";
// Additionally, change the orientation so the packing works as intended
document.documentElement.orient = "horizontal";
}
else
{
if (gOrigin & NS_ALERT_TOP)
document.documentElement.pack = "end";
}
var alertBox = document.getElementById("alertBox");
alertBox.orient = (gOrigin & NS_ALERT_HORIZONTAL) ? "vertical" : "horizontal";
// The above doesn't cause the labels in alertTextBox to reflow,
// see bug 311557. As the theme's -moz-box-align css rule gets ignored,
// we work around the bug by setting the align property.
if (gOrigin & NS_ALERT_HORIZONTAL)
{
document.getElementById("alertTextBox").align = "center";
}
sizeToContent();
// Work around a bug where sizeToContent() leaves a border outside of the content
var contentDim = document.getElementById("alertBox").boxObject;
if (window.innerWidth == contentDim.width + 1)
--window.innerWidth;
// Start with a 1px width/height, because 0 causes trouble with gtk1/2
gCurrentSize = 1;
// Determine final size
if (gOrigin & NS_ALERT_HORIZONTAL)
{
gFinalSize = window.outerWidth;
window.outerWidth = gCurrentSize;
}
else
{
gFinalSize = window.outerHeight;
window.outerHeight = gCurrentSize;
}
// Determine position
var x = gOrigin & NS_ALERT_LEFT ? screen.availLeft :
screen.availLeft + screen.availWidth - window.outerWidth;
var y = gOrigin & NS_ALERT_TOP ? screen.availTop :
screen.availTop + screen.availHeight - window.outerHeight;
// Offset the alert by 10 pixels from the edge of the screen
if (gOrigin & NS_ALERT_HORIZONTAL)
y += gOrigin & NS_ALERT_TOP ? 10 : -10;
else
x += gOrigin & NS_ALERT_LEFT ? 10 : -10;
window.moveTo(x, y);
setTimer(animateAlert, gSlideTime);
}
function animate(step)
{
gCurrentSize += step;
if (gOrigin & NS_ALERT_HORIZONTAL)
{
if (!(gOrigin & NS_ALERT_LEFT))
window.screenX -= step;
window.outerWidth = gCurrentSize;
}
else
{
if (!(gOrigin & NS_ALERT_TOP))
window.screenY -= step;
window.outerHeight = gCurrentSize;
}
}
function animateAlert()
{
if (gCurrentSize < gFinalSize)
{
animate(gSlideIncrement);
setTimer(animateAlert, gSlideTime);
}
else if(gOpenTime>0)
setTimer(animateCloseAlert, gOpenTime);
}
function animateCloseAlert()
{
if (gCurrentSize > 1)
{
animate(-gSlideIncrement);
setTimer(animateCloseAlert, gSlideTime);
}
else
closeAlert();
}
function closeAlert() {
if (gAlertListener)
gAlertListener.observe(null, "alertfinished", gAlertCookie);
window.close();
}
function onAlertClick()
{
if (gAlertListener && gAlertTextClickable)
gAlertListener.observe(null, "alertclickcallback", gAlertCookie);
}